<!-- Form {@$form_name@} START -->
<!--
1. You need Prototype javascript library to be included. Download it from http://www.prototypejs.org/
2. Image (animated gif) for waiting indicator have to be declared as follows:
Medium indicator. Javascript variable name ajax_waiting_indicator_medium_src. Example: var ajax_waiting_indicator_medium_src = 'img/indicator_medium.gif'
Please note that it is good idea image for the indicator to be preloaded (i.e. in onLoad page event).
3. Overlay image (normally png with some transperancy). Must be specified in css for  class ajax_overlay_form
4. CSS for the overlay div.
-->

{@if !$_language@}
{@assign var="_language" value="en_us"@}
{@/if@}
<script type="text/javascript">
var _tm = '{$_tm}';
var _site_mode = {$_site_mode};
var _server_error_page = '{$_server_error_page}';
var _transit_vars_par = ''{foreach from=$_transit_vars item=tvar_value key=tvar_key} + '&' + '{$tvar_key}={$tvar_value}'{/foreach};

{literal}
function submit_ajax_{@$form_name@}() {
{@foreach item=f from=$fields name=fields_loop@}
{@if $f.missing@}
	var {@$form_name@}_{@$f.name@}_par = '';
	var {@$form_name@}_{@$f.name@} = $F('{@$form_name@}_{@$f.name@}');

	if ({@$form_name@}_{@$f.name@} != null) {
		{@$form_name@}_{@$f.name@}_par = '{@$form_name@}_{@$f.name@}=1' + '&';
	}
{@/if@}{@/foreach@}

	var	pars = {@foreach item=f from=$fields name=fields_loop@}
{@if !$f.missing@}
{@if !$smarty.foreach.fields_loop.first@}			{@/if@}'{@$form_name@}_{@$f.name@}=' + encodeURIComponent($F('{@$form_name@}_{@$f.name@}')) + '&' + 
{@else@}			{@$form_name@}_{@$f.name@}_par + 
{@/if@}
{@/foreach@} 			'{@$submit@}=1' + '&' + '_tm=' + _tm + _transit_vars_par;

	fade_out_div();
	var myAjax = new Ajax.Request(
                                    "ajax/forms/{@$form_name@}_form.php",
                                    {
                                                method: 'post',
                                                onComplete: {@$form_name@}_result,
                                                onSuccess: {@$form_name@}_on_success,
                                                onFailure: {@$form_name@}_on_failure,
												parameters: pars
                                    }          );
}



function {@$form_name@}_result(req, json) {
	if (json) {
		var old_tm = _tm;
		_tm = json._tm;

		// refreshing _tm on all links that are outside of updated area
		for (var i=0; i < document.links.length; i++) {
 		  	document.links[i].href = document.links[i].href.replace(old_tm, _tm);
		}


		if (json.result_code == 1) { // OK
				switch(json.command) {
					case 'redirect':
						window.location = json.command_value;
						break;
					case 'show' :
					default :
						form_div = $('{@$form_name@}_form_div');
						form_div.innerHTML = req.responseText;
						break;
				}
		} else {
				// something is wrong
				if (_site_mode == 0) {
					//if in development mode - show the output anyway (if any).
					form_div = $('{@$form_name@}_form_div');
					form_div.innerHTML = req.responseText;
				}
		}
	} else {
		// no result_code, some serious error/exception occured.
		if (_site_mode == 1) {
			window.location = _server_error_page;
		} else {
			//if in development mode - show the output anyway (if any).
			form_div = $('{@$form_name@}_form_div');
			form_div.innerHTML = req.responseText;
		}
	}
}


function fade_out_div() {
	var overlay = $('{@$form_name@}_overlay');
	var top_div = $('{@$form_name@}_form_div');

	Position.clone(top_div, overlay)
	var image = $('{@$form_name@}_waiting');

	overlay.style.display = 'block';
	var image_top_offset = Math.round((overlay.offsetHeight - image.height) / 2);
	image.style.marginTop = image_top_offset + 'px';
}


function fade_in_div() {
	var overlay = $('{@$form_name@}_overlay');
	overlay.style.display = 'none';
}


function {@$form_name@}_on_success() {
	fade_in_div();
}


function {@$form_name@}_on_failure() {
	fade_in_div();
}

</script>
{/literal}
<div id="{@$form_name@}_form_div" style="width:800px;">
<!-- *** CUT top -->
    <table width="800"  border="0" cellspacing="0" cellpadding="0" class="form" id="{@$form_name@}_top_table">
        <tr>
            <td align="left">
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>
                            <div class="form_title">{@$form_name@}</div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <!-- If you don't want notes erase this START -->
        <tr>
            <td>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0" class="form_note">
                    <!-- Repeat this fo additional notes START -->
                    <tr>
                        <td valign="top" align="left">
                            <table width="100%"  border="0" cellspacing="0" cellpadding="4" class="form_note_title">
                                <tr>
                                    <td><img src="img/modules/form_html_tpl_static_ajax_metallic/exclamation_mark.png" border="0" alt="icon exclamation mark"  width="16" height="16" /></td>
                                    <td width="100%" align="left">Note:</td>
                                </tr>
                            </table>
                        </td>
                        <td align="left" width="99%">
                            <div class="form_note_text">Fields marked with &quot;*&quot; are mandatory.</div>
                        </td>
                    </tr>
                    <!-- Repeat this fo additional notes END-->
                </table>
            </td>
        </tr>
        <!-- If you don't want notes erase this END -->
        {@if $fields@}
        <tr>
            <td>
                <div id="{@$form_name@}">
                    <form onsubmit="submit_ajax_{@$form_name@}(); return false;" action="{@$action@}" method="{@$method@}" name="{@$form_name@}_form" enctype="{@$enctype@}"  class="form">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="left">
                                    <table width="100%"  border="0" cellspacing="0" cellpadding="0" class="form_row">
                                        {@section name=i loop=$fields@}
                                        {@if !$fields[i].not_visible@}
                                        <tr>
                                            <td class="{@if $smarty.section.i.index is odd@}form_odd_row{@else@}form_even_row{@/if@}"> {@include file="`$fields[i].tpl_file`" f=$fields[i]@} </td>
                                        </tr>
                                        {@/if@}
                                        {@/section@}
                                    </table>
                                    {@section name=i loop=$fields@}
                                    {@if $fields[i].not_visible@}
                                    {@include file="`$fields[i].tpl_file`" f=$fields[i]@}
                                    {@/if@}
                                    {@/section@} </td>
                            </tr>
                            <tr>
                                <td align="left">
                                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="submit_row">
                                        <tr>
                                            <td width="180">&nbsp;</td>
                                            <td width="100" align="left">
                                                <input name="{@$submit@}" type="submit" value="{@$submit@}" class="form_submit" />
                                            </td>
                                            <td width="50">&nbsp;</td>
                                            <td>
                                                <div class="form_cancel"><a href="{${@$form_name@}_cancel_link}">Cancel</a></div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </td>
        </tr>
        {@/if@}
    </table>
<!-- *** CUT bottom -->
</div>
<div class="ajax_overlay_form" id="{@$form_name@}_overlay" style="display:none; position: absolute; z-index: 90;" align="center"><img src="img/modules/form_html_tpl_static_ajax_metallic/indicator_medium.gif" onclick="return true;" id="{@$form_name@}_waiting" alt="" /></div>
<!-- Form {@$form_name@} END -->
